#include "SipRegistration.hpp"
#include "SipDialogSet.hpp"
#include "SipUserAgent.hpp"

#include "rutil/Logger.hxx"
#define RESIPROCATE_SUBSYSTEM Subsystem::APP

namespace wtsip{


CSipRegistration::CSipRegistration(CSipDialogSet& dlgset, const resip::Uri& local, const resip::Uri& remote):
CSipDialogBase(dlgset, local, remote) {
    m_DlgType = Registration;
    WarningLog(<<"Dialog New: " << m_CallId);
}


CSipRegistration::CSipRegistration(CSipDialogSet& dlgset, SipMessage& msg):
CSipDialogBase(dlgset, msg){
    m_DlgType = Registration;
    WarningLog(<<"Dialog New: " << m_CallId);
}


CSipRegistration::~CSipRegistration(){
    WarningLog(<<"Dialog Delete: " << m_CallId);
}


//bool CSipRegistration::onRequest(CSipClnTransaction& clntran, SipMessage& msg){
//    return true;
//}


bool CSipRegistration::onResponse(CSipClnTransaction& clntran, SipMessage& msg){
    return true;
}


bool CSipRegistration::onRequest(CSipSrvTransaction& srvtran, SipMessage& msg){
    return true;
}


//bool CSipRegistration::onResponse(CSipSrvTransaction& srvtran, SipMessage& msg){
//    return true;
//}


SipMessage* CSipRegistration::createRegister(){
    CSipUserAgent& ua = m_dlgset.getUserAgent();
    SipMessage* msg = ua.createRegisterMsg(m_RemoteNameAddr, m_LocalNameAddr);
    msg->header(h_CallId).value() = m_CallId;
    msg->header(h_From).param(p_tag) = m_LocalNameAddr.param(p_tag);
    if (m_RemoteNameAddr.exists(p_tag)){
        msg->header(h_To).param(p_tag) = m_RemoteNameAddr.param(p_tag);
    }
    msg->header(h_CSeq).sequence() = ++m_fwCSeq;
    return msg;
}


}//namespace


